package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 韩先楚
 */
@RestController
@Api(tags = "后台-套餐管理")
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private SetMealService setMealService;

    @Autowired
    private SetMealService setmealService;

    /**
     * 新增套餐
     */
    @PostMapping()
    @ApiOperation(value = "新增套餐")
    public Result addSetmeal(@RequestBody SetmealVO setmealVO) {
       log.info("新增套餐:{}", setmealVO);
       setMealService.addSetmeal(setmealVO);
       return Result.success();
    }

    /**
     * 修改套餐状态
     */
    @PostMapping("status/{status}")
    @ApiOperation(value = "修改套餐状态")
    public Result updateStatus(@PathVariable("status") Integer status,  Integer id) {
        log.info("修改套餐状态,status:{},id:{}", status, id);
        setMealService.updateStatus(id,status);
        return Result.success();
    }

    /**
     * 根据id查询套餐
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询套餐")
    public Result<SetmealVO> getSetmealById(@PathVariable("id") Integer id) {
        log.info("根据id查询套餐,id:{}", id);
        SetmealVO setmealVO = setMealService.getSetmealById(id);
        return Result.success(setmealVO);
    }

    /**
     * 分页查询套餐
     */
  @GetMapping("/page")
  @ApiOperation(value = "分页查询套餐")
    public Result<PageResult> page(Integer page,Integer pageSize
                                   ,String name,Integer status,
                                   Integer categoryId){
      log.info("分页查询套餐,page:{},pageSize:{},name:{},status:{},categoryId:{}", page, pageSize, name, status, categoryId);
      PageResult pageResult = setMealService.page(page, pageSize, name, status, categoryId);
      return Result.success(pageResult);
  }

    /**
     * 批量删除套餐
     */
    @DeleteMapping()
    @ApiOperation(value = "批量删除套餐")
    public Result deleteSetmeal(@RequestParam("ids") List<Integer> ids) {
        log.info("批量删除套餐,ids:{}", ids);
        setMealService.deleteSetmeal(ids);
        return Result.success();
    }

    /**
     * 修该套餐数据
     */
    @PutMapping
    @ApiOperation("修改套餐数据")
    public Result update(@RequestBody SetmealDTO setmealDto) {
        log.info("修改套餐数据:{}", setmealDto.getCategoryId());
        setmealService.update(setmealDto);
        return Result.success();
    }

}
